package com.heeexy.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.EmpsService;
import com.heeexy.example.util.CommonUtil;

@RestController
@RequestMapping("/emps")
public class EmpsController {
	 @Autowired
	  private EmpsService empsService;
	 
	 @RequiresPermissions("sell:list")
	    @GetMapping("/list")
	    public JSONObject list(HttpServletRequest request) {
	        return empsService.listEmps(CommonUtil.request2Json(request));
	    }
	 
	 @RequiresPermissions("sell:update")
	    @PostMapping("/updateEmps")
	    public JSONObject updateGoods(@RequestBody JSONObject requestJson) {
	       CommonUtil.hasAllRequired(requestJson, "eid,deptno,sal,edate,eage,eaddress");
	        return empsService.updateEmps(requestJson);
	    }

	 @RequiresPermissions("sell:add")
	    @PostMapping("/addEmps")
	    public JSONObject addUser(@RequestBody JSONObject requestJson) {
	        CommonUtil.hasAllRequired(requestJson, "eid,deptno,sal,edate,eage,eaddress");
	        return empsService.addEmps(requestJson);
	    }
	 
	 @RequiresPermissions("sell:delete")
	    @PostMapping("/deleteEmps")
	    public JSONObject deleteRole(@RequestBody JSONObject requestJson) {
	        CommonUtil.hasAllRequired(requestJson,"eid");
	        return empsService.deleteEmps(requestJson);
	    }

}
